package com.oa.controller.user;

import com.oa.aop.AspectException;
import com.oa.pojo.Attendance;
import com.oa.service.user.AttendanceService;
import com.oa.vo.PageResult;
import com.oa.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;
    @GetMapping("/getAttendanceList")
    public SysResult getAttendanceList(){
        return SysResult.success(attendanceService.getAttendanceList());
    }
    @PutMapping("/setAttendanceStatus")
    public SysResult setAttendanceStatus(@RequestBody Attendance attendance){
        attendanceService.setAttendanceStatus(attendance);
        return SysResult.success();
    }
    @PutMapping("/setCloseStatus")
    public SysResult setCloseStatus(@RequestBody Attendance attendance){
        attendanceService.setCloseStatus(attendance);
        return SysResult.success();
    }
    @GetMapping("/getAttendanceByIndex/{index}")
    public SysResult getAttendanceByIndex(@PathVariable String index){
        return SysResult.success(attendanceService.getAttendanceByIndex(index));
    }
    @GetMapping("/mkAttendanceList")
    @AspectException
    public SysResult mkAttendanceList() throws Exception{
        return SysResult.success(attendanceService.mkAttendanceList());
    }

    @PostMapping("/generateAttdance")
    public SysResult generateAttdance() throws Exception {
        attendanceService.mkAttendanceList();
        return SysResult.success();
    }
    @GetMapping("/getAllAttendanceList")
    public SysResult getAllAttendanceList(PageResult pageResult){
        return SysResult.success(attendanceService.getAllAttendanceList(pageResult));
    }


    /**
     * 每日定时任务,自动生成考勤记录
     * @return
     */
    @PutMapping("/dogenerateAttendanceStatus/{day}")
    public SysResult dogenerateAttendanceStatus(@PathVariable String day){
        attendanceService.dogenerateAttendanceStatus(day);
        return SysResult.success();
    }
}
